#pragma once


#include "cmd.h"
class cmdfactor
{
public:
    cmdfactor(){};
    virtual ~cmdfactor(){};
    virtual cmd* getcmd(string cmdline)=0;
};



class logincmdfactor : public cmdfactor
{
public:
    logincmdfactor(){};
    virtual ~logincmdfactor(){};
    cmd* getcmd(string cmdline) override;
};



class logoutcmdfactor : public cmdfactor
{
public:
    logoutcmdfactor(){};
    virtual ~logoutcmdfactor(){};
    cmd* getcmd(string cmdline) override;
};

struct cmdfactors
{
    logincmdfactor logincmdf;
    logoutcmdfactor logoutcmdf;
    cmdfactors(){
        logincmdf=logincmdfactor();
        logoutcmdf=logoutcmdfactor();
    };

    cmd* getcmdptr(string cmdline)
    {
        if(cmdline==string("")) {
            cout<<"empty line recved\n";
            return nullptr;
        }else{
            istringstream iss(cmdline);
            string token;
            iss>>token;
            if(token==string("login"))
            {
                cmd* cmdptr = logincmdf.getcmd(cmdline);
                return cmdptr;
            }else if(token==string("logout"))
            {
                cmd* cmdptr = logoutcmdf.getcmd(cmdline);
                return cmdptr;
            }else{
                cout<<"wrong cmd recved\n";
                return nullptr;
            }
        }
    }
};    

extern struct cmdfactors cfs;